package xkp.lesson;

import xkp.lesson.dao.UserInfoDao;
import xkp.lesson.entity.UserInfoEntity;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static  Scanner scanner;
    private static UserInfoDao userInfoDao;
    public static void main(String[] args) throws SQLException {
        scanner = new Scanner(System.in);
        System.out.println("系统登录");
        System.out.println("请输入用户名....");
        String userName = scanner.nextLine();
        System.out.println("请输入密码....");
        String userPwd = scanner.nextLine();
        userInfoDao = new UserInfoDao();
        if(userInfoDao.login(userName,userPwd) != null){
            showMainUi();
        }else{
            System.out.println("登录失败");
        }

    }

    private static void showMainUi() throws SQLException {
        while(true) {
            System.out.println("1、展示数据");
            System.out.println("2、删除数据");
            System.out.println("3、退出系统");
            System.out.println("请选择....");
            String cmd = scanner.nextLine();
            if (cmd.equals("1")) {
                List<UserInfoEntity> list = userInfoDao.selectAll();
                //list.forEach(System.out::println);
                for (UserInfoEntity userInfo : list) {
                    System.out.println("userName:" + userInfo.getUserName() + "||userPwd:" + userInfo.getUserPwd());
                }
            }

            if (cmd.equals("2")) {
                System.out.println("功能完善中....");
            }

            if(cmd.equals("3")){
                break;
            }
        }
    }


}
